# coding:utf-8
import time

from lib.base import Base

from page.android import train_select_order_page, train_order_page, train_order_details_page, train_online_service_page

__author__ = 'weixin.yuan'


class TrainOrder(Base):
    """我的订单"""
    def __init__(self, method_name):
        Base.__init__(self, methodName=method_name)

        """
        本页元素
        """
        self.btn_list = [
            train_order_page.elements['待出行按钮'],
            train_order_page.elements['待支付按钮'],
            train_order_page.elements['退款单按钮'],
        ]
        self.all_btn = train_order_page.elements['全部按钮']
        self.select_order_btn = train_order_page.elements['订单查询按钮']
        self.consultation_btn = train_order_page.elements['咨询按钮']
        self.order_details_btn = train_order_page.elements['订单详情按钮']

        """
        外部页面元素
        """
        self.select_order_input = train_select_order_page.elements['订单输入框']
        self.order_details_title1 = train_order_details_page.elements['订单详情title1']
        self.order_details_title2 = train_order_details_page.elements['订单详情title2']
        self.online_service_title = train_online_service_page.elements['在线客服title']

    def test_train_order(self):
        """我的订单测试"""
        self.open_schema_android('6016')

        for btn in self.btn_list:
            time.sleep(1)
            print(btn)
            self.click(btn)

        print(self.all_btn)
        self.click(self.all_btn, is_necessary=True)

        self.click(self.select_order_btn)
        self.check(self.select_order_input)
        self.back()

        self.click(self.consultation_btn)
        self.check(self.online_service_title)
        self.back()

        self.click(self.order_details_btn)
        time.sleep(10)
        if not self.is_exits(self.order_details_title1) and not self.is_exits(self.order_details_title2):
            raise AssertionError("查看订单详情失败")
